﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Lenovo.CFI.BLL;
using Lenovo.CFI.BLL.DicMgr;
using Lenovo.CFI.BLL.Sys;
using Lenovo.CFI.Common;
using Lenovo.CFI.Web.Helper;
using Lenovo.CFI.Common.Sys;
using Lenovo.CFI.Common.Dic;

namespace Lenovo.CFI.Web.VP
{
    public partial class Stat4 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                for (int i = 2012; i < 2020; i++)
                {
                    this.DdlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                this.DdlYear.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true;

                this.GvList.Visible = false;

                this.Page.Form.DefaultButton = this.BtnStat.UniqueID;
            }
        }


        DateTime from;
        DateTime to;
        protected void BtnStat_Click(object sender, EventArgs e)
        {
            int year = Convert.ToInt32(this.DdlYear.SelectedValue);

            this.from = new DateTime(year, 1, 1);
            this.to = new DateTime(year, 12, 31);

            List<object[]> managerNumbers = new StatBl().GmoManagerNumberByTime(from, to);

            this.GvList.Visible = true;
            this.GvList.DataSource = managerNumbers;
            this.GvList.DataBind();
        }

        string lastGmo = null;
        protected void GvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)    // 数据行
            {
                object[] number = (object[])e.Row.DataItem;

                e.Row.CssClass = "empty";

                string dateF = this.from.ToString("yyyy-MM-dd");
                string dateT = this.to.ToString("yyyy-MM-dd");

                if (lastGmo == number[1].ToString())
                {
                    e.Row.Cells[0].Visible = false;
                    e.Row.Cells[1].Visible = false;
                }
                else
                {
                    int[] vp = (int[])number[13];
                    ((Literal)(e.Row.FindControl("LtrGmo"))).Text = number[1].ToString();
                    e.Row.Cells[0].RowSpan = vp[11];
                    ((Literal)(e.Row.FindControl("LtrGmoSummary"))).Text = String.Format("{0}/{1}/{2}/{3}", vp[10], vp[0], vp[2], vp[8]);
                    e.Row.Cells[1].RowSpan = vp[11];

                    lastGmo = number[1].ToString();
                }

                ((Literal)(e.Row.FindControl("LtrManager"))).Text = number[0].ToString();

                ((Literal)(e.Row.FindControl("LtrManagerSummary"))).Text = number[12].ToString();

                ((Literal)(e.Row.FindControl("LtrProduct"))).Text = number[0].ToString();

                ((Literal)(e.Row.FindControl("LtrCproject"))).Text = number[4].ToString();

                ((Literal)(e.Row.FindControl("LtrAward"))).Text = number[10].ToString();

                //((Literal)(e.Row.FindControl("LtrManagerSummary"))).Text = String.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                //    UrlHelper.GenerateUrl("search", "topicdf", dateF, "topicdt", dateT, "stat", "1", "manager", number[0].ToString()), number[12]);

                //((Literal)(e.Row.FindControl("LtrProduct"))).Text = String.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                //    UrlHelper.GenerateUrl("search", "topicdf", dateF, "topicdt", dateT, "stat", "1", "manager", number[0].ToString(), "action", NextAction.PRODUCT), number[2]);

                //((Literal)(e.Row.FindControl("LtrCproject"))).Text = String.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                //    UrlHelper.GenerateUrl("search", "topicdf", dateF, "topicdt", dateT, "stat", "1", "manager", number[0].ToString(), "action", NextAction.CPROJECT), number[4]);

                //((Literal)(e.Row.FindControl("LtrAward"))).Text = String.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                //    UrlHelper.GenerateUrl("search", "topicdf", dateF, "topicdt", dateT, "stat", "1", "manager", number[0].ToString(), "award", "1"), number[10]);
            }
        }
    }
}